#include"serialize/equipment.h"

Equipment::Equipment()
{
    id = 0;
    type = 0;
    name = "";
    description = "";
    star_level = 0;
    attack_min = 0;
    attack_max = 0;
    defense_min = 0;
    defense_max = 0;
    energy_recover_min = 0;
    energy_recover_max = 0;
    ammo_recover_min = 0;
    ammo_recover_max = 0;
    exp_addon_min = 0;
    exp_addon_max = 0;
    money_addon_min = 0;
    money_addon_max = 0;
}

Equipment::Equipment(qint32 _id,
                     qint8 _type,
                     QString _name,
                     QString _description,
                     qint8 _star_level,
                     qint32 _attack_min,
                     qint32 _attack_max,
                     qint32 _defense_min,
                     qint32 _defense_max,
                     qint8 _energy_recover_min,
                     qint8 _energy_recover_max,
                     qint8 _ammo_recover_min,
                     qint8 _ammo_recover_max,
                     qint8 _exp_addon_min,
                     qint8 _exp_addon_max,
                     qint8 _money_addon_min,
                     qint8 _money_addon_max)
{
    id = _id;
    type = _type;
    name = _name;
    description = _description;
    star_level = _star_level;
    attack_min = _attack_min;
    attack_max = _attack_max;
    defense_min = _defense_min;
    defense_max = _defense_max;
    energy_recover_min = _energy_recover_min;
    energy_recover_max = _energy_recover_max;
    ammo_recover_min = _ammo_recover_min;
    ammo_recover_max = _ammo_recover_max;
    exp_addon_min = _exp_addon_min;
    exp_addon_max = _exp_addon_max;
    money_addon_min = _money_addon_min;
    money_addon_max = _money_addon_max;
}

Equipment::Equipment(const Equipment &e)
{
    id = e.id;
    type = e.type;
    name = e.name;
    description = e.description;
    star_level = e.star_level;
    attack_min = e.attack_min;
    attack_max = e.attack_max;
    defense_min = e.defense_min;
    defense_max = e.defense_max;
    energy_recover_min = e.energy_recover_min;
    energy_recover_max = e.energy_recover_max;
    ammo_recover_min = e.ammo_recover_min;
    ammo_recover_max = e.ammo_recover_max;
    exp_addon_min = e.exp_addon_min;
    exp_addon_max = e.exp_addon_max;
    money_addon_min = e.money_addon_min;
    money_addon_max = e.money_addon_max;
}

Equipment& Equipment::operator=(const Equipment& e)
{
    if(&e == this)
        return *this;

    id = e.id;
    type = e.type;
    name = e.name;
    description = e.description;
    star_level = e.star_level;
    attack_min = e.attack_min;
    attack_max = e.attack_max;
    defense_min = e.defense_min;
    defense_max = e.defense_max;
    energy_recover_min = e.energy_recover_min;
    energy_recover_max = e.energy_recover_max;
    ammo_recover_min = e.ammo_recover_min;
    ammo_recover_max = e.ammo_recover_max;
    exp_addon_min = e.exp_addon_min;
    exp_addon_max = e.exp_addon_max;
    money_addon_min = e.money_addon_min;
    money_addon_max = e.money_addon_max;

    return *this;
}

Equipment::~Equipment()
{

}

ostream& operator<<(ostream& os,Equipment& e)
{
    os<<"EquipmentInfo:"<<endl;
    os<<"id:"<<(int)e.id<<endl;
    os<<"type:"<<(int)e.type<<endl;
    os<<"name:"<<e.name.toStdString()<<endl;
    os<<"description:"<<e.description.toStdString()<<endl;
    os<<"star_level:"<<(int)e.star_level<<endl;
    os<<"attack_min:"<<(int)e.attack_min<<endl;
    os<<"attack_max:"<<(int)e.attack_max<<endl;
    os<<"defense_min:"<<(int)e.defense_min<<endl;
    os<<"defense_max: "<<(int)e.defense_max<<endl;
    os<<"energy_recover_min: "<<(int)e.energy_recover_min<<endl;
    os<<"energy_recover_max: "<<(int)e.energy_recover_max<<endl;
    os<<"ammo_recover_min: "<<(int)e.ammo_recover_min<<endl;
    os<<"ammo_recover_min: "<<(int)e.ammo_recover_max<<endl;
    os<<"exp_addon_min: "<<(int)e.exp_addon_min<<endl;
    os<<"exp_addon_max: "<<(int)e.exp_addon_max<<endl;
    os<<"money_addon_min: "<<(int)e.money_addon_min<<endl;
    os<<"money_addon_max: "<<(int)e.money_addon_max<<endl;
    return os;
}

QDataStream& operator<<(QDataStream& ds,Equipment& e)
{
    ds<<e.id;
    ds<<e.type;
    ds<<e.name.toUtf8().data();
    ds<<e.description.toUtf8().data();
    ds<<e.star_level;
    ds<<e.attack_min;
    ds<<e.attack_max;
    ds<<e.defense_min;
    ds<<e.defense_max;
    ds<<e.energy_recover_min;
    ds<<e.energy_recover_max;
    ds<<e.ammo_recover_min;
    ds<<e.ammo_recover_max;
    ds<<e.exp_addon_min;
    ds<<e.exp_addon_max;
    ds<<e.money_addon_min;
    ds<<e.money_addon_max;

    return ds;
}

QDataStream& operator>>(QDataStream& ds,Equipment& e)
{
    char* temp;
    ds>>e.id;
    ds>>e.type;
    ds>>temp;
    e.name = QString::fromUtf8(temp);
    delete[] temp;
    ds>>temp;
    e.description = QString::fromUtf8(temp);
    delete[] temp;
    ds>>e.star_level;
    ds>>e.attack_min;
    ds>>e.attack_max;
    ds>>e.defense_min;
    ds>>e.defense_max;
    ds>>e.energy_recover_min;
    ds>>e.energy_recover_max;
    ds>>e.ammo_recover_min;
    ds>>e.ammo_recover_max;
    ds>>e.exp_addon_min;
    ds>>e.exp_addon_max;
    ds>>e.money_addon_min;
    ds>>e.money_addon_max;

    return ds;
}
